package com.xiguaji.boot.eventbus;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import java.util.List;
import java.util.concurrent.ExecutorService;

public class EventBusTemplate {

  private EventBus eventBus;

  private AsyncEventBus asyncEventBus;

  public EventBusTemplate(List<IEventListener> listenerList, ExecutorService executorService) {
    eventBus = new EventBus("SyncEventBus");
    asyncEventBus = new AsyncEventBus("AsyncEventBus", executorService);
    listenerList.forEach(eventBus::register);
    listenerList.forEach(asyncEventBus::register);
  }

  public void post(Event event) {
    eventBus.post(event);
  }

  public void postAsync(Event event) {
    asyncEventBus.post(event);
  }
}
